package com.qersoft.dao;

import java.sql.*;

public class DatabaseUtils {

    private static final String URL = "jdbc:mysql://localhost:3306/exam_system"; // 数据库连接URL
    private static final String USER = "root";  // 数据库用户名
    private static final String PASSWORD = "password";  // 数据库密码

    // 获取数据库连接
    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(URL, USER, PASSWORD);
    }

    // 关闭数据库连接
    public static void closeConnection(Connection conn, Statement stmt, ResultSet rs) {
        try {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
